/**
 * related to detail.ui
 * 
 * @Author : chenglm
 * @Timestamp : 2016-07-04
 */
var app = sm("do_App");
var page = sm("do_Page");
var hashdata = mm("do_HashData");

var do_LinearLayout_main = ui("do_LinearLayout_main");
var do_LinearLayout_item = ui("do_LinearLayout_item");
var do_Button_order = ui("do_Button_order");
var common = require("common");
var homemakingUtil = require("url/homemaking");
var qqHttp = require("helper/http");

//andriod返回键
page.on("back", function() {
    app.closePage();
});

/* 头部 */
var headerAout = ui("do_ALayout_header");
var addheader = headerAout.add("header", "source://view/reuse/header.ui", 0, 0);
var header = ui("header");
//左上角-返回
var headerLeft = ui(addheader+".headerLeft");
headerLeft.on("touch", function() {
    app.closePage()
});
var labelTitle = ui(addheader+".labelTitle");

var type;
var pubitemVoList;
//页面装载完成后，开始初始化工作
page.on("loaded", function(){
	//读取当前页面的传入参数
	var data = page.getData();
	qqHttp.post(homemakingUtil.url.type.detailType, {id:data.id}, function(data) {
		//deviceone.print(JSON.stringify(data));
		type = data.type;
		pubitemVoList = data.pubitemVoList;
		labelTitle.text = data.type.name;
		for(var i=pubitemVoList.length-1;i >= 0; i--) {
			var addItem = do_LinearLayout_item.add("item"+i, "source://view/homemaking/detail/detailItem.ui", 0, 0);
			var do_Label_1 = ui(addItem+".do_Label_1");
			var do_Label_2 = ui(addItem+".do_Label_2");
			do_Label_1.text = "参考价:" + pubitemVoList[i].name;
			do_Label_2.text = pubitemVoList[i].price + "元/" + pubitemVoList[i].unit;
		}
		
		if (data.dictList) {
			var dictList = data.dictList;
			for (var k = dictList.length-1; k >= 0; k--) {
				if (dictList[k].hasImg == "0") {
					var dictUi = do_LinearLayout_main.add("dict"+k, "source://view/homemaking/detail/detailIntroduce.ui", "do_LinearLayout_item");
					ui(dictUi+".label_title").text = dictList[k].dictTitle;
					ui(dictUi+".label_content").text = dictList[k].dictContent;
				} else {
					var dictUi = do_LinearLayout_main.add("dict"+k, "source://view/homemaking/detail/detailIntroduce2.ui", "do_LinearLayout_item");
					ui(dictUi+".label_title").text = dictList[k].dictTitle;
					ui(dictUi+".gridView_content").items = dictList[k].dictContents;
				}
			}
		}
	});
});

do_Button_order.on("touch",function(){
	/*if (type) {
		common.open("source://view/homemaking/detail/toOrder.ui",{"typeId":type.id},"","pay_product_back");
	}*/
	app.closePage();
});
